//import java.awt.EventQueue;

import javax.swing.JFrame;

//import java.awt.GridBagLayout;

import javax.swing.JButton;

//import java.awt.GridBagConstraints;
//import java.awt.Insets;

import javax.swing.SwingConstants;
import javax.swing.JLabel;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;

import java.awt.Color;

import javax.swing.JCheckBox;
//import javax.swing.JTextField;
import javax.swing.JFormattedTextField;
//import javax.swing.AbstractAction;

import java.awt.event.ActionEvent;

//import javax.swing.Action;

import java.awt.event.ActionListener;
import java.text.NumberFormat;


public class Gra {

    public JFrame frame;
    private JFormattedTextField txtWielkoscZakladu;
    private NumberFormat amountFormat = NumberFormat.getNumberInstance();
    //private String wymiana;
    private Start start;

    private Controller kontroler;
    private JCheckBox chckbxNewCheckBox;
    private JCheckBox checkBox;
    private JCheckBox checkBox_1;
    private JCheckBox checkBox_2;
    private JCheckBox checkBox_3;
    
    private JButton btnCheck;
    private JButton btnNewButton_1; // raise
    private JButton btnNewButton; // bet
    private JButton btnCall;
    private JButton btnFold;
    private JButton btnNewButton_2; // wymiana
    private JButton btnAllin;
    
    private JLabel lblNewLabel;
    JLabel lblGracz;
    
    JLabel lblNewLabel_1;   //karta 0
    JLabel lblSpade;        //kolor 0
    JLabel lblK;            //karta 1
    JLabel lblHeart;        //kolor 1
    JLabel lblQ;            //karta 2
    JLabel lblDiamond;      //kolor 2
    JLabel lblW;            //karta 3
    JLabel lblClub;         //kolor 3
    JLabel label_7;         //karta 4
    JLabel lblSpade_1;      //kolor 4
    
    JLabel lblNewLabel_2;   //kasa gracz 1
    JLabel label;           //kasa gracz 2
    JLabel label_2;         //kasa gracz 3
    JLabel label_4;         //kasa gracz 4
    
    JLabel label_6;         //kasa stol
    JLabel lblStawka;       //stawka
    
    JLabel label_3;         //wygrane gracz 1
    JLabel label_5;         //wygrane gracz 2
    JLabel label_8;         //wygrane gracz 3
    JLabel label_9;         //wygrane gracz 4
    
    
    
    
    
    /**
     * Launch the application.
     */
    /*public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    Gra window = new Gra();
                    window.frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }*/

    /**
     * Create the application.
     */
    public Gra(Controller kontroler,Start start) {
        this.kontroler = kontroler;
        this.start = start;
        initialize();
    }

    /**
     * Initialize the contents of the frame.
     */
    private void initialize() {
        frame = new JFrame();
        frame.setResizable(false);
        frame.setBounds(100, 100, 709, 394);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().setLayout(null);
        
        btnCheck = new JButton("Check");
        btnCheck.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                kontroler.Check();
            }
        });
        btnCheck.setBounds(10, 134, 102, 23);
        frame.getContentPane().add(btnCheck);
        btnCheck.setEnabled(false);
        
        btnNewButton = new JButton("Bet");
        btnNewButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                kontroler.Bet(Integer.parseInt(txtWielkoscZakladu.getText()));  
            }
        });
        btnNewButton.setBounds(10, 162, 102, 23);
        frame.getContentPane().add(btnNewButton);
        btnNewButton.setEnabled(false);
        
        btnNewButton_1 = new JButton("Raise");
        btnNewButton_1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                kontroler.Raise(Integer.parseInt(txtWielkoscZakladu.getText()));  
            }
        });
        btnNewButton_1.setBounds(10, 190, 102, 23);
        frame.getContentPane().add(btnNewButton_1);
        btnNewButton_1.setEnabled(false);
        
        btnCall = new JButton("Call");
        btnCall.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                kontroler.Call();   
            }
        });
        btnCall.setBounds(10, 224, 102, 23);
        frame.getContentPane().add(btnCall);
        btnCall.setEnabled(false);
        
        btnFold = new JButton("Fold");
        btnFold.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                kontroler.Fold();   
            }
        });
        btnFold.setBounds(10, 252, 102, 23);
        frame.getContentPane().add(btnFold);
        btnFold.setEnabled(false);
        
        btnAllin = new JButton("All-In");
        btnAllin.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                kontroler.all_In();
            }
        });
        btnAllin.setBounds(10, 280, 102, 23);
        frame.getContentPane().add(btnAllin);
        btnAllin.setEnabled(false);
        
        
        //--------------------------------------------------------------------------------------------------------------------------------------------
        lblNewLabel = new JLabel("Komunikaty");
        lblNewLabel.setBackground(Color.WHITE);
        lblNewLabel.setOpaque(true);
        lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
        lblNewLabel.setBounds(122, 11, 370, 157);
        frame.getContentPane().add(lblNewLabel);
        //lblNewLabel.setText("<html>Wlazl kotek na plotek<br>pierdolnal go mlotek<br>siekierka dobila<br>i kotka zabila.<br>:|</html>");
        lblNewLabel.setText(""); 
        
        lblNewLabel_1 = new JLabel("A");
        lblNewLabel_1.setOpaque(true);
        lblNewLabel_1.setForeground(Color.BLACK);
        lblNewLabel_1.setBackground(Color.WHITE);
        lblNewLabel_1.setHorizontalAlignment(SwingConstants.CENTER);
        lblNewLabel_1.setBounds(122, 200, 66, 47);
        frame.getContentPane().add(lblNewLabel_1);
        
        lblSpade = new JLabel("SPADE");
        lblSpade.setOpaque(true);
        lblSpade.setHorizontalAlignment(SwingConstants.CENTER);
        lblSpade.setForeground(Color.BLACK);
        lblSpade.setBackground(Color.WHITE);
        lblSpade.setBounds(122, 256, 66, 47);
        frame.getContentPane().add(lblSpade);
        
        lblK = new JLabel("K");
        lblK.setOpaque(true);
        lblK.setHorizontalAlignment(SwingConstants.CENTER);
        lblK.setForeground(Color.BLACK);
        lblK.setBackground(Color.WHITE);
        lblK.setBounds(198, 200, 66, 47);
        frame.getContentPane().add(lblK);
        
        lblHeart = new JLabel("HEART");
        lblHeart.setOpaque(true);
        lblHeart.setHorizontalAlignment(SwingConstants.CENTER);
        lblHeart.setForeground(Color.BLACK);
        lblHeart.setBackground(Color.WHITE);
        lblHeart.setBounds(198, 256, 66, 47);
        frame.getContentPane().add(lblHeart);
        
        lblQ = new JLabel("Q");
        lblQ.setOpaque(true);
        lblQ.setHorizontalAlignment(SwingConstants.CENTER);
        lblQ.setForeground(Color.BLACK);
        lblQ.setBackground(Color.WHITE);
        lblQ.setBounds(274, 200, 66, 47);
        frame.getContentPane().add(lblQ);
        
        lblDiamond = new JLabel("DIAMOND");
        lblDiamond.setOpaque(true);
        lblDiamond.setHorizontalAlignment(SwingConstants.CENTER);
        lblDiamond.setForeground(Color.BLACK);
        lblDiamond.setBackground(Color.WHITE);
        lblDiamond.setBounds(274, 256, 66, 47);
        frame.getContentPane().add(lblDiamond);
        
        lblW = new JLabel("W");
        lblW.setOpaque(true);
        lblW.setHorizontalAlignment(SwingConstants.CENTER);
        lblW.setForeground(Color.BLACK);
        lblW.setBackground(Color.WHITE);
        lblW.setBounds(350, 200, 66, 47);
        frame.getContentPane().add(lblW);
        
        lblClub = new JLabel("CLUB");
        lblClub.setOpaque(true);
        lblClub.setHorizontalAlignment(SwingConstants.CENTER);
        lblClub.setForeground(Color.BLACK);
        lblClub.setBackground(Color.WHITE);
        lblClub.setBounds(350, 256, 66, 47);
        frame.getContentPane().add(lblClub);
        
        label_7 = new JLabel("10");
        label_7.setOpaque(true);
        label_7.setHorizontalAlignment(SwingConstants.CENTER);
        label_7.setForeground(Color.BLACK);
        label_7.setBackground(Color.WHITE);
        label_7.setBounds(426, 200, 66, 47);
        frame.getContentPane().add(label_7);
        
        lblSpade_1 = new JLabel("SPADE");
        lblSpade_1.setOpaque(true);
        lblSpade_1.setHorizontalAlignment(SwingConstants.CENTER);
        lblSpade_1.setForeground(Color.BLACK);
        lblSpade_1.setBackground(Color.WHITE);
        lblSpade_1.setBounds(426, 256, 66, 47);
        frame.getContentPane().add(lblSpade_1);
        
        JLabel lblTwojeKarty = new JLabel("Twoje Karty");
        lblTwojeKarty.setHorizontalAlignment(SwingConstants.CENTER);
        lblTwojeKarty.setBounds(233, 168, 152, 30);
        frame.getContentPane().add(lblTwojeKarty);
        
        lblGracz = new JLabel("GRACZ #");
        lblGracz.setBackground(Color.WHITE);
        lblGracz.setHorizontalAlignment(SwingConstants.CENTER);
        lblGracz.setBounds(10, 11, 102, 20);
        frame.getContentPane().add(lblGracz);
        

        
        chckbxNewCheckBox = new JCheckBox("1");
        chckbxNewCheckBox.setHorizontalAlignment(SwingConstants.CENTER);
        chckbxNewCheckBox.setBounds(122, 310, 66, 23);
        frame.getContentPane().add(chckbxNewCheckBox);
        chckbxNewCheckBox.setEnabled(false);
        
        checkBox = new JCheckBox("2");
        checkBox.setHorizontalAlignment(SwingConstants.CENTER);
        checkBox.setBounds(198, 310, 66, 23);
        frame.getContentPane().add(checkBox);
        checkBox.setEnabled(false);
        
        checkBox_1 = new JCheckBox("3");
        checkBox_1.setHorizontalAlignment(SwingConstants.CENTER);
        checkBox_1.setBounds(274, 310, 66, 23);
        frame.getContentPane().add(checkBox_1);
        checkBox_1.setEnabled(false);
        
        checkBox_2 = new JCheckBox("4");
        checkBox_2.setHorizontalAlignment(SwingConstants.CENTER);
        checkBox_2.setBounds(350, 310, 66, 23);
        frame.getContentPane().add(checkBox_2);
        checkBox_2.setEnabled(false);
        
        checkBox_3 = new JCheckBox("5");
        checkBox_3.setHorizontalAlignment(SwingConstants.CENTER);
        checkBox_3.setBounds(426, 310, 66, 23);
        frame.getContentPane().add(checkBox_3);
        checkBox_3.setEnabled(false);
        

        
        btnNewButton_2 = new JButton("Wymiana");
        btnNewButton_2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                kontroler.wymiana();   
            }
        });
        btnNewButton_2.setBounds(10, 310, 102, 23);
        frame.getContentPane().add(btnNewButton_2);
        btnNewButton_2.setEnabled(false);
        
        txtWielkoscZakladu = new JFormattedTextField(amountFormat);
        txtWielkoscZakladu.setHorizontalAlignment(SwingConstants.CENTER);
        txtWielkoscZakladu.setText("0");
        txtWielkoscZakladu.setBounds(10, 103, 102, 20);
        frame.getContentPane().add(txtWielkoscZakladu);
        txtWielkoscZakladu.setColumns(10);
        txtWielkoscZakladu.setEnabled(false);
        
        JLabel lblGracz_1 = new JLabel("GRACZ 1");
        lblGracz_1.setHorizontalAlignment(SwingConstants.CENTER);
        lblGracz_1.setBounds(551, 82, 89, 14);
        frame.getContentPane().add(lblGracz_1);
        
        lblNewLabel_2 = new JLabel("N/A");
        lblNewLabel_2.setBackground(Color.WHITE);
        lblNewLabel_2.setOpaque(true);
        lblNewLabel_2.setHorizontalAlignment(SwingConstants.CENTER);
        lblNewLabel_2.setBounds(502, 105, 89, 23);
        frame.getContentPane().add(lblNewLabel_2);
        
        label = new JLabel("N/A");
        label.setOpaque(true);
        label.setHorizontalAlignment(SwingConstants.CENTER);
        label.setBackground(Color.WHITE);
        label.setBounds(502, 162, 89, 23);
        frame.getContentPane().add(label);
        
        JLabel lblGracz_2 = new JLabel("GRACZ 2");
        lblGracz_2.setHorizontalAlignment(SwingConstants.CENTER);
        lblGracz_2.setBounds(551, 138, 89, 14);
        frame.getContentPane().add(lblGracz_2);
        
        label_2 = new JLabel("N/A");
        label_2.setOpaque(true);
        label_2.setHorizontalAlignment(SwingConstants.CENTER);
        label_2.setBackground(Color.WHITE);
        label_2.setBounds(502, 224, 89, 23);
        frame.getContentPane().add(label_2);
        
        JLabel lblGracz_3 = new JLabel("GRACZ 3");
        lblGracz_3.setHorizontalAlignment(SwingConstants.CENTER);
        lblGracz_3.setBounds(551, 199, 89, 14);
        frame.getContentPane().add(lblGracz_3);
        
        label_4 = new JLabel("N/A");
        label_4.setOpaque(true);
        label_4.setHorizontalAlignment(SwingConstants.CENTER);
        label_4.setBackground(Color.WHITE);
        label_4.setBounds(502, 279, 89, 23);
        frame.getContentPane().add(label_4);
        
        JLabel lblGracz_4 = new JLabel("GRACZ 4");
        lblGracz_4.setHorizontalAlignment(SwingConstants.CENTER);
        lblGracz_4.setBounds(551, 256, 89, 14);
        frame.getContentPane().add(lblGracz_4);
        
        label_6 = new JLabel("N/A");
        label_6.setOpaque(true);
        label_6.setHorizontalAlignment(SwingConstants.CENTER);
        label_6.setBackground(Color.WHITE);
        label_6.setBounds(502, 48, 89, 23);
        frame.getContentPane().add(label_6);
        
        JLabel lblStol = new JLabel("STOL");
        lblStol.setHorizontalAlignment(SwingConstants.CENTER);
        lblStol.setBounds(502, 33, 89, 14);
        frame.getContentPane().add(lblStol);
        
        JLabel lblWygrane = new JLabel("Wygrane");
        lblWygrane.setHorizontalAlignment(SwingConstants.CENTER);
        lblWygrane.setBounds(601, 55, 89, 14);
        frame.getContentPane().add(lblWygrane);
        
        label_3 = new JLabel("N/A");
        label_3.setOpaque(true);
        label_3.setHorizontalAlignment(SwingConstants.CENTER);
        label_3.setBackground(Color.WHITE);
        label_3.setBounds(601, 104, 89, 23);
        frame.getContentPane().add(label_3);
        
        label_5 = new JLabel("N/A");
        label_5.setOpaque(true);
        label_5.setHorizontalAlignment(SwingConstants.CENTER);
        label_5.setBackground(Color.WHITE);
        label_5.setBounds(601, 162, 89, 23);
        frame.getContentPane().add(label_5);
        
        label_8 = new JLabel("N/A");
        label_8.setOpaque(true);
        label_8.setHorizontalAlignment(SwingConstants.CENTER);
        label_8.setBackground(Color.WHITE);
        label_8.setBounds(601, 224, 89, 23);
        frame.getContentPane().add(label_8);
        
        label_9 = new JLabel("N/A");
        label_9.setOpaque(true);
        label_9.setHorizontalAlignment(SwingConstants.CENTER);
        label_9.setBackground(Color.WHITE);
        label_9.setBounds(601, 280, 89, 23);
        frame.getContentPane().add(label_9);
        
        JLabel lblIloscZetonow = new JLabel("Ilosc zetonow");
        lblIloscZetonow.setHorizontalAlignment(SwingConstants.CENTER);
        lblIloscZetonow.setBounds(502, 11, 89, 14);
        frame.getContentPane().add(lblIloscZetonow);
        
        JButton btnNext = new JButton("Next");
        btnNext.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                kontroler.next();
            }
        });
        btnNext.setBounds(502, 310, 89, 23);
        frame.getContentPane().add(btnNext);
        
        JLabel lblAktualnaStawka = new JLabel("Aktualna stawka");
        lblAktualnaStawka.setHorizontalAlignment(SwingConstants.CENTER);
        lblAktualnaStawka.setBounds(20, 42, 92, 14);
        frame.getContentPane().add(lblAktualnaStawka);
        
        lblStawka = new JLabel("stawka");
        lblStawka.setHorizontalAlignment(SwingConstants.CENTER);
        lblStawka.setOpaque(true);
        lblStawka.setBackground(Color.WHITE);
        lblStawka.setBounds(10, 67, 102, 25);
        frame.getContentPane().add(lblStawka);
        
        JMenuBar menuBar = new JMenuBar();
        frame.setJMenuBar(menuBar);
        
        JMenu mnMenu = new JMenu("Menu");
        menuBar.add(mnMenu);
        
        JMenuItem mntmHalp = new JMenuItem("Nowa Gra");
        mntmHalp.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                Nowa_Gra dialog = new Nowa_Gra(kontroler,start);
                dialog.setVisible(true);
            }
        });
        mnMenu.add(mntmHalp);
        
        JMenuItem mntmExit = new JMenuItem("Exit");
        mntmExit.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });
        mnMenu.add(mntmExit);
    }

    JButton[] getButtons(){
        JButton[] buttons = new JButton[7];
        buttons[0] = btnCheck;
        buttons[1] = btnNewButton_1; // raise
        buttons[2] = btnNewButton; // bet
        buttons[3] = btnCall;
        buttons[4] = btnFold;
        buttons[5] = btnNewButton_2; // wymiana
        buttons[6] = btnAllin;
        return buttons;
    }
    
    JCheckBox[] getCheckBoxes(){
        JCheckBox[] chckBoxArray = new JCheckBox[5];
        chckBoxArray[0] = chckbxNewCheckBox;
        chckBoxArray[1] = checkBox;
        chckBoxArray[2] = checkBox_1;
        chckBoxArray[3] = checkBox_2;
        chckBoxArray[4] = checkBox_3;
        return chckBoxArray;
    }

    JLabel getKomunikaty(){
        return lblNewLabel;
    }
    
    JLabel getNrGracza(){
        return lblGracz;
    }
    
    JFormattedTextField getZaklad(){
        return txtWielkoscZakladu;
    }
    
    JLabel[][] getKarty(){
        JLabel[][] karty = new JLabel[5][2];
        
        karty[0][0] = lblNewLabel_1;   //karta 0
        karty[0][1] = lblSpade;        //kolor 0
        karty[1][0] = lblK;            //karta 1
        karty[1][1] = lblHeart;        //kolor 1
        karty[2][0] = lblQ;            //karta 2
        karty[2][1] = lblDiamond;      //kolor 2
        karty[3][0] = lblW;            //karta 3
        karty[3][1] = lblClub;         //kolor 3
        karty[4][0] = label_7;         //karta 4
        karty[4][1] = lblSpade_1;      //kolor 4
        
        return karty;
    }
    
    JLabel[] getKasaLabel(){
        JLabel[] getKasaLabel = new JLabel[4];
        getKasaLabel[0] = lblNewLabel_2;
        getKasaLabel[1] = label;        
        getKasaLabel[2] = label_2;      
        getKasaLabel[3] = label_4;      
        
        return getKasaLabel;
    }
    
    JLabel getKasaStol(){
        return label_6;
    }
    
    JLabel getStawka(){
        return lblStawka;
    }
    
    JLabel[] getWygraneLabel(){
        JLabel[] getWygraneLabel = new JLabel[4];
        getWygraneLabel[0] = label_3;
        getWygraneLabel[1] = label_5;
        getWygraneLabel[2] = label_8;
        getWygraneLabel[3] = label_9;
        
        return getWygraneLabel;
    }
}
